<style>
    .layui-table-cell {
        padding:1px 3px;
        height:auto;
        overflow:visible;
        text-overflow:inherit;
        white-space:normal;
        word-break: break-all;line-height:19px;
    }
    .analytics th{padding:3px 6px;font-weight:bold;}
    .bold{font-weight:bold;}
    th .layui-table-cell{text-align:center;font-size:13px;line-height:19px;}
    .layui-form-item .shotselect{width:120px;}
    .layui-form-pane .layui-form-label{width:auto;}
    .layui-layer-btn{margin-bottom: 40px;}
    .layui-form-item{margin-bottom: 0px;}
    .hover{color: blue}
</style>
<div class="fixed-bar" >
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('',[])}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline show">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline show">
                <label class="layui-form-label">sku</label>
                <div class="layui-input-inline">
                    <input type="text" name="sku" lay-verify="" placeholder="输入sku" class="layui-input">
                </div>
            </div>
            <div class="layui-inline show">
                <label class="layui-form-label">来源帐号</label>
                <div class="layui-input-inline">
                    {:Form::select('is_auto_import', '', [''=> '请选择']+config('mimo.order_from'), '', '')}
                </div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">节点进度</label>
                <div class="layui-input-inline">
                    {:Form::select('status', '', $status_select, '', '')}
                </div>
            </div>
            <div class="layui-inline show">
                <label class="layui-form-label">委外类型</label>
                <div class="layui-input-inline">
                    {:Form::select('group_out_type', '', $group_out_type_select, '', '')}
                </div>
            </div>
            <div class="layui-inline show">
                <label class="layui-form-label ">发货日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="time_send_0_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择创建日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline show">
                <label class="layui-form-label ">车间回货日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="time_return_0_date_range" readonly="" id="create_date_range1" lay-verify="" placeholder="选择创建日期" class="layui-input">
                </div>
            </div>

            <div class="layui-inline show">
                <label class="layui-form-label">委外工厂</label>
                <div class="layui-input-inline xm-select-demo" id="demo2" style="width: auto;min-width: 250px;">
                </div>
            </div>
            <div class="layui-inline">
                <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
<!--                <button type="button" class="layui-btn layui-btn-primary hisi-export show">导出</button>-->
            </div>
        </div>
    </form>
</div>
<table id="dataTable" lay-filter="demoEvent"></table>



{include file="system@block/layui" /}

<script type="text/html" id="picTpl">
    <span class="lay-pic-container" src="{{ d.pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
	</span>
</script>
<script type="text/html" id="skuTpl">
    <span >{{ d.is_auto_import_name }}</span> <br>
    <span class="copy-item">{{ d.client_ordernum }}</span> <br>
    <span class="copy-item">{{ d.sku }}</span></br>
    <span >{{ d.ft_name }}/{{ d.ft_group_name }}</span>
</script>
<script type="text/html" id="countTpl">
    <span >{{ d.sum_shicai_count }}/{{ d.sum_jiaohuo_count }}/{{ d.sum_jiaohuo_tail_count }}/{{ d.sum_store_count }}</span>
</script>
<script type="text/html" id="return_numTpl">
    <span >{{ d.return_fr_num }}/{{ d.return_ot_num }}</span>
</script>
<script type="text/html" id="caichuang_over_timeTpl">
    <span>裁剪完成：{{ d.caichuang_over_time }}</span> <br/>
    <span>发货：{{ d.time_send_0 }}</span> <br/>
    <span>车间回货：{{ d.time_return_0 }}</span>
</script>
<script type="text/html" id="time_return_2Tpl">
    <span>退货：{{ d.time_return_1 }}</span> <br/>
    <span>外协：{{ d.time_return_2 }}</span>
</script>
<script type="text/html" id="materialTpl">
    {{# if(d.is_share== 1){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-orange">共</a>
    {{# } }}
    <span class="copy-item">{{ d.mInfo.name }}</span><br />
    {{d.mInfo.color}}
</script>
<script type="text/html" id="unit">
    {{d.mInfo.unit}}
</script>
<script type="text/html" id="color">
    {{d.mInfo.color}}
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('billList')}?stall_feed_id={{d.id}}&status_real=1140" class="hisi-iframe blue bill-list-a" hisi-data="{width: '70%', height: '70%'}" title="费用单">帐单明细</a></br>
    <!--    <a href="{:url('stallCost/stallCostDetail')}?stall_feed_id={{d.id}}" title="费用单" class="hisi-iframe blue" hisi-data="{width: '70%', height: '90%'}">查看费用单</a>-->
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn-group fr">
        <a data-href="{:url('check')}?status=1102&type=all" class="hide layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon back">驳回</a>&nbsp;&nbsp;

        <a data-href="{:url('accountPayment')}" class="hide layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon account-payment">已付款</a>
    </div>
</script>
<script type="text/html" id="detailTpl">
    <a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" title="明细表" class="hisi-iframe blue" hisi-data="{width: '100%', height: '100%'}">打开</a>
    <!--    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" method="get" id="hisi-table-search">-->
    <a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}&export=1" style="cursor:pointer;border: none" class="blue hisi-export">下载</a>
    <!--    <form>-->
</script>

<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script type="text/javascript">
    layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;
        var initialize=0,second_initialize=0,first_init=0,changetab=0;
        laydate.render({
            elem: '#create_date_range'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range').val(value);
                $('#layui-laydate1').remove();//关闭面板
            }
        });
        laydate.render({
            elem: '#create_date_range1'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range1').val(value);
                $('#layui-laydate2').remove();//关闭面板
            }
        });


        table.render({
            elem: '#dataTable'
            ,url: '{:url("", [])}' //数据接口
            ,page: true //开启分页
            //,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [5,20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            // ,width:document.documentElement.clientWidth-50
            ,defaultToolbar: ['exports', 'print']
            ,cols: [[ //表头
                // {type:'checkbox'}
                {field:'pic',title : '图片', templet:'#picTpl',width:110}
                ,{field: 'col2', title: '来源/订单号/sku/委外工厂', templet: '#skuTpl' ,width:200}
                ,{field: 'col3', title: '裁床/车间/尾部/MES入仓总数', templet: '#countTpl' ,width:100}
                ,{field: 'col4', title: '退货回货/外协回货', templet: '#return_numTpl' ,width:150}
                // ,{field: 'sum_shicai_count', title: '裁床数'}
                // ,{field: 'sum_jiaohuo_count', title: '车间总数'}
                // ,{field: 'sum_jiaohuo_tail_count', title: '尾部总数'}
                // ,{field: 'sum_store_count', title: 'MES入仓总数'}
                ,{field: 'hope_shipment_time', title: '工厂预交期',width:130}
                ,{field: 'status_txt', title: '进度状态',width:70}
                ,{field: 'col5', title: '裁剪完成/发货/车间回货-日期', templet: '#caichuang_over_timeTpl',width:190}
                ,{field: 'col6', title: '退货/外协-回货日期', templet: '#time_return_2Tpl',width:180}

                // ,{field: 'caichuang_over_time', title: '裁剪完成日期',width:130}
                // ,{field: 'time_send_0', title: '发货日期',width:130}
                // ,{field: 'time_return_0', title: '车间回货日期',width:130}
                ,{field: 'time_send_0_time_return_0', title: '车间耗时',width:80}

                ,{field: 'after_out_type_txt', title: '委外类型',width:70}
                // ,{field: 'order_price', title: 'MES加工费',width:80}
                ,{field: 'cost_little', title: '小计',width:70}
                ,{field: 'group_unit_price', title: '委外倍率',width:70}
                ,{field: 'order_price_res', title: '委外单价',width:70}
                // ,{field: 'ft2_group_name', title: '委外工厂',width:130}
                // ,{field: 'time_return_2', title: '委外回货日期',width:130}
                // ,{field: 'time_send_2', title: '委外发料日期'}



                ,{field: 'kuchen_num', title: '库存数',width:70}
                ,{field: 'chayi_num', title: '差异数',width:70}


                ,{field: 'after_return_time', title: '返工计时',width:80}
                ,{field: 'after_return_price', title: '返工金额',width:80}
                // ,{field: 'col3', title: '操作',templet:'#buttonTpl'}
            ]]
            ,done: function(res, curr, count){
                var data=res.data;
                var status=res.status;
                for (var i in data){
                    $('#stall-ids-'+data[i]['id']).val(data[i]['stall_id']);
                }
                layui.form.render();
                table.on('edit(demoEvent)', function(obj){
                    var value = obj.value //得到修改后的值
                        ,d = obj.data //得到所在行所有键值
                        ,field = obj.field; //得到字段
                    var id=d.id;

                    $.ajax({
                        type: "POST",
                        url: "{:url('editUnit')}",
                        data: "id="+d.id+"&field="+field+"&value="+value,
                        dataType:"json",
                        success: function(res){
                            if (res.code == 1) {
                                layer.msg(res.msg, {icon: 1});
                            } else {
                                layer.msg(res.msg, {icon: 2,anim: 6});
                            }
                        }
                    });
                });
                skuCount_set();
            }
        });
    });

    var factory_ids_json = {:json_encode($factory_ids)};

    var demo2 = xmSelect.render({
        el: '#demo2',
        name:'factory_ids',
        autoRow: true,
        filterable: true,
        tree: {
            show: true,
            showFolderIcon: true,
            showLine: true,
            indent: 20,
            expandedKeys: [ -1 ],
            lazy: true,
            load: function(item, cb){
                console.log(item);
                console.log(cb);
            }
        },
        toolbar: {
            show: true,
            list: ['ALL', 'REVERSE', 'CLEAR']
        },
        height: 'auto',
        data(){
            return factory_ids_json
        }
    })

    //统计数据
    function skuCount_set() {
        $.ajax({
            type: "POST",
            url: "{:url('OutCheckOrder/otherReportListData')}",
            data: $('#hisi-table-search').serialize(),
            dataType:"json",
            success: function(res){
                if (res.code == 1) {
                    var d=res.data;
                    var html='<span class="layui-laypage-count">总单数：&nbsp;'+d.sum_order_id+'个</span>' +
                        '<span class="layui-laypage-count">下单：&nbsp;'+d.sum_order_count+'件</span>'+
                        '<span class="layui-laypage-count">裁床：&nbsp;'+d.sum_shicai_count+'件</span>'+
                        '<span class="layui-laypage-count">车间：&nbsp;'+d.sum_jiaohuo_count+'件</span>'+
                        '<span class="layui-laypage-count">尾部：&nbsp;'+d.sum_jiaohuo_tail_count+'件</span>'+
                        '<span class="layui-laypage-count">MES入仓：&nbsp;'+d.sum_store_count+'件</span>'+
                        '<span class="layui-laypage-count">退货回货：&nbsp;'+d.return_fr_num+'件</span>'+
                        '<span class="layui-laypage-count">外协回货：&nbsp;'+d.return_ot_num+'件</span>'
                    ;
                    $(".layui-table-page div .layui-box").append(html);
                } else {
                    layer.msg(res.msg, {icon: 2,anim: 6});
                }
            }
        });
    }
</script>